package com.iclient.job;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import com.plugins.server.MQServer;
import com.plugins.server.MsgConsumer;
import com.rabbitmq.client.Channel;

/**
 * spring容器启动后执行
 * @author user
 *
 */
public class BootstrapService implements ApplicationListener<ContextRefreshedEvent>{

	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		//避免springmvc执行两次
		if(event.getApplicationContext().getParent() == null){
			System.out.println("==============启动进程===============");
			MQServer mqServer = MQServer.getServer();
			Channel channel = mqServer.initConnection("sina", "sina.weibo", "");
			MsgConsumer msgConsumer = new MsgConsumer(channel);
			mqServer.startConsume(msgConsumer, "sina.weibo");
		}
	}

}
